//
//  BSThemeCell.m
//  BaiSi
//
//  Created by Sycamore on 16/5/3.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "BSThemeCell.h"
#import "BSTopView.h"
#import "BSPictureView.h"
#import "BSThemeCellModel.h"
#import "BSThemeItem.h"
#import "BSVideoView.h"
#import "BSVoiceView.h"
#import <SDImageCache.h>
#import "BSHotCommentView.h"
#import "BSBottomView.h"
@interface BSThemeCell ()

@property (nonatomic,weak) BSTopView *topView;
@property (nonatomic,weak) BSPictureView *pictureView;
@property (nonatomic,weak) BSVideoView *videoView;
@property (nonatomic,weak) BSVoiceView *voiceView;
@property (nonatomic,weak) BSHotCommentView *hotCommentView;
@property (nonatomic,weak) BSBottomView *bottomView;
@end

@implementation BSThemeCell

- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 10;
    frame.size.height -= 10;
    [super setFrame:frame];
    
}

- (void)awakeFromNib {
    // Initialization code
    self.autoresizingMask = UIViewAutoresizingNone;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        //注意图片需要拉伸
        UIImage *image = [UIImage imageNamed:@"mainCellBackground"] ;
        image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
        self.backgroundView = [[UIImageView alloc]initWithImage:image];
        
        BSTopView *topView = [BSTopView topView];
        _topView = topView;
        [self.contentView addSubview:topView];
        
        BSPictureView *pictureView = [BSPictureView pictureView];
        _pictureView = pictureView;
        [self.contentView addSubview:pictureView];
        
        BSVideoView *videoView = [BSVideoView viewFromNib];
        _videoView = videoView;
        [self.contentView addSubview:videoView];
        
        BSVoiceView *voiceView = [BSVoiceView viewFromNib];
        _voiceView = voiceView;
        [self.contentView addSubview:voiceView];
        
        BSHotCommentView *hotCommentView = [BSHotCommentView viewFromNib];
        _hotCommentView = hotCommentView;
        [self.contentView addSubview:hotCommentView];
        
        BSBottomView *bottomView = [BSBottomView viewFromNib];
        _bottomView = bottomView;
        [self.contentView addSubview:bottomView];
        
        
        
    }
    return self;
}

- (void)setCellModel:(BSThemeCellModel *)cellModel
{
    _cellModel = cellModel;
    
    _topView.frame = cellModel.topViewFrame;
    _topView.item = cellModel.item;

    //pictureView
    if (cellModel.item.type == ThemeTypePicture) {
        _pictureView.frame = cellModel.middleViewFrame;
        _pictureView.item = cellModel.item;
        _pictureView.hidden = NO;
        _videoView.hidden = YES;
        _voiceView.hidden = YES;

    }else if (cellModel.item.type == ThemeTypeVideo)
    {
        //videoView
        _videoView.frame = cellModel.middleViewFrame;
        _videoView.item = cellModel.item;
        _videoView.hidden = NO;
        _pictureView.hidden = YES;
        _voiceView.hidden = YES;
    }else if (cellModel.item.type == ThemeTypeVoice)
    {
        _voiceView.frame = cellModel.middleViewFrame;
        _voiceView.item = cellModel.item;
        
        _voiceView.hidden = NO;
        _pictureView.hidden = YES;
        _videoView.hidden = YES;
    }
    else{
        _pictureView.hidden = YES;
        _videoView.hidden = YES;
        _voiceView.hidden = YES;
    }
    
    //是否显示最热评论
    if (cellModel.item.commentItem) {
        _hotCommentView.hidden = NO;
        _hotCommentView.frame = cellModel.hotCommentViewFrame;
        _hotCommentView.item = cellModel.item;
    }
    else{
        _hotCommentView.hidden = YES;
    }
    
    //显示底部view
    _bottomView.frame = cellModel.bottomViewFrame;
    _bottomView.item = cellModel.item;

}
@end
